local skel = fk.CreateSkill {
  name = "efengqi__xiongluan",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["efengqi__xiongluan"] = "雄乱",
  [":efengqi__xiongluan"] = "限定技，准备阶段，你可以废除装备区和判定区，令一名其他角色本回合不能使用或打出手牌。此后你的【杀】和装备牌均视为【兵临城下】。",

  ["#efengqi__xiongluan-choose"] = "雄乱：你可废除装备区和判定区，令一名其他角色本回合不能使用或打出手牌。本局【杀】和装备视为【兵临城下】",
  ["@@efengqi__xiongluan-turn"] = "被雄乱",
  ["@@efengqi__xiongluan_owner"] = "雄乱",

  ["$efengqi__xiongluan1"] = "北地枭雄，乱世不败！！",
  ["$efengqi__xiongluan2"] = "雄据宛城，虽乱世可安！",
}

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and player.phase == Player.Start then
      return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 and
      (#player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, skill_name = skel.name, targets = room:getOtherPlayers(player, false), prompt = "#efengqi__xiongluan-choose"
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local eqipSlots = player:getAvailableEquipSlots()
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(eqipSlots, Player.JudgeSlot)
    end
    room:abortPlayerArea(player, eqipSlots)
    if not to.dead then
      room:setPlayerMark(to, "@@efengqi__xiongluan-turn", 1)
    end
    if not player.dead then
      room:setPlayerMark(player, "@@efengqi__xiongluan_owner", 1)
      player:filterHandcards()
    end
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    if player:getMark("@@efengqi__xiongluan-turn") > 0 then
      local subcards = Card:getIdList(card)
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player.player_cards[Player.Hand], id)
      end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@efengqi__xiongluan-turn") > 0 then
      local subcards = Card:getIdList(card)
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player.player_cards[Player.Hand], id)
      end)
    end
  end,
})

skel:addEffect("filter", {
  card_filter = function(self, card, player)
    return player and card and player:getMark("@@efengqi__xiongluan_owner") ~= 0 and
    table.contains(player.player_cards[Player.Hand], card.id) and (card.trueName == "slash" or card.type == Card.TypeEquip)
  end,
  view_as = function(self, _, card)
    local c = Fk:cloneCard("enemy_at_the_gates", card.suit, card.number)
    c.skillName = skel.name
    return c
  end,
})


return skel
